import { createContext, useReducer } from "react"

const initState = {
  count: 60
}

const reducer = (state, action) => {
  switch (action.type) {
    case 'set_count':
      return { ...state, count: action.value}
    default:
      return state
  }
}

export const context = createContext()

const ContextProvider = ({children}) => {
  const [state, dispatch] = useReducer(reducer, initState)
  return (
    <context.Provider value={{state, dispatch}}>
      {children}
    </context.Provider>
  )
}

export default ContextProvider